<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<div>
		<p>爱好</p>
		<input type="checkbox" value="choose" id = "all">全选<br>
		<div class="items">
			<input type="checkbox" value="read">阅读<br>
			<input type="checkbox" value="swim">游泳<br>
			<input type="checkbox" value="program">编程<br>
			<input type="checkbox" value="smoke">抽烟<br>
			<input type="checkbox" value="game">游戏<br>
			<input type="checkbox" value="drink">喝酒<br>
		</div>
		<button>全选</button>
		<button>全不选</button>
		<button>反选</button>
	</div>
</body>
<script>
	var btn = document.querySelectorAll("button");
	var inp = document.querySelectorAll("input");
	// var boolean = true;
	
	//全选
	btn[0].onclick = function(){

		for(var i = 0;i<inp.length;i++){
			inp[i].checked = "checked";
			// inp[i].boolean = true;
		}

	}

	//全不选
	btn[1].onclick = function(){

		for(var i = 0;i<inp.length;i++){
			inp[i].checked = "";
			// inp[i].boolean = false;
		}
	}

	
	//反选
	btn[2].onclick = function(){

		for(var i = 0;i<inp.length;i++){
			
			if(inp[i].checked){

				inp[i].checked = "";
			}else{

				inp[i].checked = "checked";
			}
		}
	}

</script>
</html>